//
//  FirstViewController.m
//  uplife
//
//  Created by ZhangCheng on 2018/12/20.
//  Copyright © 2018年 ZhangCheng. All rights reserved.
//

#import "FirstViewController.h"
#import "YQYPiecewiseView.h"
#import "UIImageView+WebCache.h"
#import "DetailSuperViewController.h"
#import "ColorCircleView.h"
#import "WebViewController.h"
@interface FirstViewController ()<YQYPiecewiseViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,weak)IBOutlet UIView *segmentSuperView;
@property(nonatomic,weak)IBOutlet UIView *huoBiSuperView;
@property(nonatomic,weak)IBOutlet UIView *shaiXuanSuperView;

@property(nonatomic,weak)IBOutlet UITableView *firstTableView;
@property(nonatomic,weak)IBOutlet UIView *secView;
@property(nonatomic,weak)IBOutlet UILabel *shaiXuanResultLabel;
@property(nonatomic,assign)NSInteger currentShaiXuanIndex;
@property(nonatomic,weak)IBOutlet UITableView *secTableView;

@property(nonatomic,assign)NSInteger currentHuoBiIndex;
@property(nonatomic,strong)IBOutlet UIPickerView *pickerView;
@property(nonatomic,strong)IBOutlet UILabel *currentHuoBiLabel;
@property(nonatomic,strong)IBOutlet UIView *pickerViewSuperView;
@property(nonatomic,strong)IBOutlet UIView *pickerViewSuperView2;
@property(nonatomic,weak)IBOutlet UIPickerView *pickerView2;
@property(nonatomic,strong)NSArray *yearsArray;

@property(nonatomic,strong)IBOutlet UIView *zongZiChanCell;
@property(nonatomic,strong)NSArray *wuYeArray;
@property(nonatomic,strong)NSArray *dataArray;
@property(nonatomic,strong)NSDictionary *shouYeDic;

@property(nonatomic,weak)IBOutlet UILabel *zongJiLabel1;
@property(nonatomic,weak)IBOutlet UILabel *zongJiLabel2;
@property(nonatomic,weak)IBOutlet UILabel *zongJiLabel3;
@property(nonatomic,weak)IBOutlet UILabel *zongJiLabel4;
@property(nonatomic,weak)IBOutlet UILabel *zongJiLabel5;

@property(nonatomic,weak)IBOutlet UIView *huanZhuangTuSuperView;
@property(nonatomic,weak)IBOutlet UIView *colorView1;
@property(nonatomic,weak)IBOutlet UIView *colorView2;
@property(nonatomic,weak)IBOutlet UIView *colorView3;
@end

@implementation FirstViewController
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (pickerView==self.pickerView) {
        return [ZCTool sharedInstance].huoBiArray.count;
    }else{
        if (component==0) {
            return 3;
        }else{
            NSInteger index = [pickerView selectedRowInComponent:0];
            if (index==0) {
                return self.yearsArray.count;
            }else if (index==1){
                return 12;
            }else{
                return 4;
            }
        }
    }
}

- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
    return pickerView==self.pickerView?1:2;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (pickerView==self.pickerView2) {
        if (component==0) {
            return @[@"年",@"月",@"季度"][row];
        }else{
            NSInteger index = [pickerView selectedRowInComponent:0];
            if (index==0) {
                return self.yearsArray[row];
            }else if(index==1){
                return @[@"一月",@"二月",@"三月",@"四月",@"五月",@"六月",@"七月",@"八月",@"九月",@"十月",@"十一月",@"十二月"][row];
            }else{
                return @[@"第一季度",@"第二季度",@"第三季度",@"第四季度"][row];
            }
        }
    }else
        return [ZCTool sharedInstance].huoBiArray[row][@"value"];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (self.pickerView2==pickerView) {
        if (component==0) {
            [pickerView reloadComponent:1];
        }
    }
}

-(IBAction)showPickerView2{
    self.pickerViewSuperView2.alpha=0.0f;
    self.pickerViewSuperView2.hidden = NO;
    [UIView animateWithDuration:0.25f animations:^{
        self.pickerViewSuperView2.alpha=1.0f;
    }];
}

-(IBAction)closePickerView2{
    [UIView animateWithDuration:0.25f animations:^{
        self.pickerViewSuperView2.alpha=0.0f;
    } completion:^(BOOL finished) {
        self.pickerViewSuperView2.hidden = YES;
    }];
}

-(IBAction)yuLanAction{
    [self closePickerView2];
    NSString *urlString = [NSString stringWithFormat:@"%@/realty/export-earnings.do?exportType=%@&exportVaule=%@",JSXF_HOST,@([self.pickerView2 selectedRowInComponent:0]+1),[self.pickerView2 selectedRowInComponent:0]==0?self.yearsArray[[self.pickerView2 selectedRowInComponent:1]]:@([self.pickerView2 selectedRowInComponent:1]+1)];
    
    [SVProgressHUD show];
    
    [ZCWebServiceHelper requestWithMethod:GET andUrlStr:urlString andParameters:nil andFinished:^(id response, NSURLSessionDataTask *dataTask) {
        [SVProgressHUD dismiss];
        if (![response[@"data"] isKindOfClass:[NSString class]]) {
            NSDictionary *dic = response;
            [self performSegueWithIdentifier:@"toWeb" sender:dic[@"data"][@"pdf"]];
        }
    }];
    
}

-(void)detailViewPickerViewDidClose{
    [[ZCTool sharedInstance]saveSelectedHuoBi:[ZCTool sharedInstance].huoBiArray[[self.pickerView selectedRowInComponent:0]]];
    [self.currentHuoBiLabel setText:[NSString stringWithFormat:@"%@",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"value"]]];
    [self sendRequests];
}
-(IBAction)showPickerView{
    [self.pickerView reloadAllComponents];
    self.pickerViewSuperView.alpha=0.0f;
    self.pickerViewSuperView.hidden = NO;
    [UIView animateWithDuration:0.25f animations:^{
        self.pickerViewSuperView.alpha=1.0f;
    }];
}

-(IBAction)closePickerView{
    [UIView animateWithDuration:0.25f animations:^{
        self.pickerViewSuperView.alpha=0.0f;
    } completion:^(BOOL finished) {
        self.pickerViewSuperView.hidden = YES;
        [self detailViewPickerViewDidClose];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSCalendar *gregorian = [[NSCalendar alloc]
       initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
      // 获取当前日期
    NSDate* dt = [NSDate date];
      // 定义一个时间字段的旗标，指定将会获取指定年、月、日、时、分、秒的信息
    NSDateComponents* comp = [gregorian components: NSCalendarUnitYear
     fromDate:dt];
    NSMutableArray *mArray = [[NSMutableArray alloc]init];
    
    for (NSInteger n=0; n<10; n++) {
        [mArray addObject:[NSString stringWithFormat:@"%@",@(comp.year-n)]];
    }
    self.yearsArray = [[NSArray alloc]initWithArray:mArray];
    
    // Do any additional setup after loading the view, typically from a nib.
    [self.segmentSuperView setFrame:CGRectMake(0, 0, self.view.frame.size.width - 32.0f, 44.0f)];
    [self.huoBiSuperView.layer setBorderColor:[UIColor colorWithRed:132.0f/255.0f green:138.0f/255.0f blue:152.0f/255.0f alpha:1.0f].CGColor];
    [self.shaiXuanSuperView.layer setBorderColor:[UIColor colorWithRed:132.0f/255.0f green:138.0f/255.0f blue:152.0f/255.0f alpha:1.0f].CGColor];
    
    self.zongZiChanCell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    self.zongZiChanCell.layer.shadowColor = [UIColor colorWithRed:190/255.0 green:147/255.0 blue:79/255.0 alpha:0.1].CGColor;
    self.zongZiChanCell.layer.shadowOffset = CGSizeMake(0,4);
    self.zongZiChanCell.layer.shadowOpacity = 1;
    self.zongZiChanCell.layer.shadowRadius = 12;
    self.zongZiChanCell.layer.cornerRadius = 5;
    
    self.currentShaiXuanIndex = 1;
    [self creatSegument];
    if ([ZCTool sharedInstance].currentSelectedHuoBiDic) {
        [self.currentHuoBiLabel setText:[NSString stringWithFormat:@"%@",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"value"]]];
    }
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self sendRequests];
}

-(void)sendRequests{
    [self sendRequestForLoadWuYeData];
    [self sendRequestForLoadData];
    [self sendRequestForLoadShouYeData];
}

-(void)sendRequestForLoadData{
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    // 获取当前日期
    NSDate* dt = [NSDate date];
    // 定义一个时间字段的旗标，指定将会获取指定年、月、日、时、分、秒的信息
    unsigned unitFlags = NSCalendarUnitYear;
    // 获取不同时间字段的信息
    NSDateComponents* comp = [gregorian components: unitFlags
                                          fromDate:dt];
    
    //    NSString *urlString = [NSString stringWithFormat:@"%@/realty/room-earning.do?roomId=%@&accountDate=%@&moneyType=CNY",JSXF_HOST,self.roomId,@(self.currentSelectedYear)];
    NSString *urlString = [NSString stringWithFormat:@"%@/receipts/list.do?paymentYear=%@&moneyType=%@",JSXF_HOST,@(comp.year),[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"]];
    
    [SVProgressHUD show];
    
    [ZCWebServiceHelper requestWithMethod:GET andUrlStr:urlString andParameters:nil andFinished:^(id response, NSURLSessionDataTask *dataTask) {
        [SVProgressHUD dismiss];
        if (![response[@"data"] isKindOfClass:[NSString class]]) {
            NSDictionary *dic = response;
            self.dataArray = dic[@"data"][@"dataList"];
            [self.firstTableView reloadData];
        }
    }];
}
-(void)sendRequestForLoadWuYeData{
    NSString *urlString = [NSString stringWithFormat:@"%@/realty/list.do?typeCode=%@&moneyTypeCode=%@",JSXF_HOST,self.currentShaiXuanIndex==1?@"HOUSE":@"BUILD",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"]];
    
    [SVProgressHUD show];
    
    [ZCWebServiceHelper requestWithMethod:GET andUrlStr:urlString andParameters:nil andFinished:^(id response, NSURLSessionDataTask *dataTask) {
        [SVProgressHUD dismiss];
        if (![response[@"data"] isKindOfClass:[NSString class]]) {
            NSDictionary *dic = response;
            self.wuYeArray = dic[@"data"][@"dataList"];
            [self.secTableView reloadData];
        }
    }];
}

-(void)sendRequestForLoadShouYeData{
    NSString *urlString = [NSString stringWithFormat:@"%@/realty/count-asset.do?moneyTypeCode=%@",JSXF_HOST,[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"]];
    
    [SVProgressHUD show];
    
    [ZCWebServiceHelper requestWithMethod:GET andUrlStr:urlString andParameters:nil andFinished:^(id response, NSURLSessionDataTask *dataTask) {
        [SVProgressHUD dismiss];
        if (![response[@"data"] isKindOfClass:[NSString class]]) {
            NSDictionary *dic = response;
            self.shouYeDic = dic[@"data"];
            [self resetShouYeData];
        }
        
    }];
}

-(void)resetShouYeData{
//    self.zongJiLabel1.text = [NSString stringWithFormat:@"￥%@(%@%@)",self.shouYeDic[@"totalBuyJPrice"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.shouYeDic[@"totalBuyPrice"]];
//    self.zongJiLabel2.text = [NSString stringWithFormat:@"￥%@(%@%@)",self.shouYeDic[@"totalJMoney"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.shouYeDic[@"totalMoney"]];
//    self.zongJiLabel3.text = [NSString stringWithFormat:@"￥%@(%@%@)",self.shouYeDic[@"totalJZZC"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.shouYeDic[@"totalZZC"]];
//    self.zongJiLabel4.text = [NSString stringWithFormat:@"￥%@(%@%@)",self.shouYeDic[@"totalJReceipts"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.shouYeDic[@"totalReceipts"]];
//    self.zongJiLabel5.text = [NSString stringWithFormat:@"￥%@(%@%@)",self.shouYeDic[@"Jbalance"],[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],self.shouYeDic[@"balance"]];
    
    
    float a=((NSNumber*)self.shouYeDic[@"totalZZC"]).floatValue,b=((NSNumber*)self.shouYeDic[@"balance"]).floatValue,c=((NSNumber*)self.shouYeDic[@"totalReceipts"]).floatValue;
    
    ColorCircleView *view = [[ColorCircleView alloc] initWithFrame:CGRectMake(0,0, self.huanZhuangTuSuperView.frame.size.width, self.huanZhuangTuSuperView.frame.size.height)];
    
    view.circleArray =@[@{@"strokeColor":self.colorView2.backgroundColor, @"precent":@(a/(a+b+c))},
                          @{@"strokeColor":self.colorView1.backgroundColor,@"precent":@(b/(a+b+c))},
                          @{@"strokeColor":self.colorView3.backgroundColor,@"precent":@(c/(a+b+c))}];
    
    [self.huanZhuangTuSuperView addSubview:view];
    
    self.zongJiLabel1.text = [NSString stringWithFormat:@"%@%@",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],FORMAT_PRICE(self.shouYeDic[@"totalMoney"])];
    self.zongJiLabel2.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.shouYeDic[@"balance"])];
    self.zongJiLabel3.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.shouYeDic[@"totalZZC"])];
    self.zongJiLabel4.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.shouYeDic[@"totalReceipts"])];
    self.zongJiLabel5.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(self.shouYeDic[@"totalBuyPrice"])];
    if ([[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"] isEqualToString:@"JPY"]) {
        self.zongJiLabel5.text = [NSString stringWithFormat:@"¥%@",FORMAT_PRICE(self.shouYeDic[@"totalBuyJPrice"])];
    }else{
        self.zongJiLabel5.text = [NSString stringWithFormat:@"¥%@\n(%@%@)",FORMAT_PRICE(self.shouYeDic[@"totalBuyJPrice"]),[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],FORMAT_PRICE(self.shouYeDic[@"totalBuyPrice"])];
    }

}

- (void)creatSegument
{
    NSArray *arr = [NSArray arrayWithObjects:@"资产信息",@"物业列表", nil];
    YQYPiecewiseView *piecew = [[YQYPiecewiseView alloc] initWithFrame:CGRectMake(0, 0, self.segmentSuperView.frame.size.width, self.segmentSuperView.frame.size.height)];
    piecew.type = PiecewiseInterfaceTypeMobileLin;
    piecew.delegate = self;
    piecew.linColor = [UIColor colorWithRed:203/255.0 green:172/255.0 blue:116/255.0 alpha:1.0];
    piecew.textNormalColor = [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1.0];
//    piecew.textNormalColor = [UIColor whiteColor];
    piecew.textSeletedColor = [UIColor colorWithRed:203/255.0 green:172/255.0 blue:116/255.0 alpha:1.0];
    piecew.textFont = [UIFont systemFontOfSize:16];
    [piecew loadTitleArray:arr];
    [self.segmentSuperView addSubview:piecew];
}

-(void)piecewiseView:(YQYPiecewiseView *)piecewiseView index:(NSInteger)index
{
    self.firstTableView.hidden = index!=0;
    self.secView.hidden = index==0;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.firstTableView) {
        return MIN(4,self.dataArray.count) + 1;
    }else{
        return self.wuYeArray.count;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (tableView == self.firstTableView) {
        return 1;
    }else{
        return 1;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (tableView == self.firstTableView) {
        UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerView"];
        if (!headerView) {
            headerView = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"headerView"];
            [headerView setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40.0f)];
            UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15.0f, 15.0f, 100.0f, 16.0f)];
            titleLabel.tag = 1;
            [titleLabel setFont:[UIFont fontWithName:@"HiraginoSans-W6" size: 16]];
            [titleLabel setTextColor: [UIColor colorWithRed:28/255.0 green:32/255.0 blue:41/255.0 alpha:1.0]];
            [headerView.contentView addSubview:titleLabel];
            
            UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-90.0f, 15.0f, 75.0f, 21.0f)];
            btn.backgroundColor = [UIColor colorWithRed:203/255.0 green:172/255.0 blue:116/255.0 alpha:1.0];
            btn.layer.cornerRadius = 10.5;
            NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"查看更多..." attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HiraginoSans-W3" size: 10],NSForegroundColorAttributeName: [UIColor colorWithRed:28.0f/255.0f green:32.0f/255.0f blue:41.0f/255.0f alpha:1.0f]}];
            [btn setAttributedTitle:string forState:UIControlStateNormal];
            btn.tag = 2;
            [btn addTarget:self action:@selector(chaKanGengDuoAction) forControlEvents:UIControlEventTouchUpInside];
            [headerView.contentView addSubview:btn];
            [headerView.contentView setBackgroundColor:[UIColor clearColor]];
        }
        UILabel *titleLabel = [headerView viewWithTag:1];
        UIButton *btn = [headerView viewWithTag:2];
        
            [titleLabel setText:@"汇款履历"];
            btn.hidden = NO;
        
        
        return headerView;
    }else{
        return nil;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView==self.firstTableView) {
        return 40.0f;
    }else{
        return 0.0f;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==self.firstTableView) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:(indexPath.row==0?@"cell2":@"cell3") forIndexPath:indexPath];
//        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
        if (indexPath.row!=0) {
            NSDictionary *dic = self.dataArray[indexPath.row - 1];
            UILabel *label1 = [cell viewWithTag:1];
            UILabel *label2 = [cell viewWithTag:2];
            UILabel *label3 = [cell viewWithTag:3];
            UILabel *label4 = [cell viewWithTag:4];
            
            label1.text = [NSString stringWithFormat:@"%@",dic[@"paymentTime"]];
            label2.text = [NSString stringWithFormat:@"%@",dic[@"profitInterval"]];
            if ([[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"] isEqualToString:@"JPY"]) {
                label3.text = [NSString stringWithFormat:@"%@",FORMAT_PRICE(dic[@"money"])];
            }else{
                label3.text = [NSString stringWithFormat:@"%@\n(%@%@)",FORMAT_PRICE(dic[@"money"]),[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],FORMAT_PRICE(dic[@"targetMoney"])];
            }
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:label3.text attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HiraginoSans-W3" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:46.0f/255.0f green:52.0f/255.0f blue:65.0f/255.0f alpha:1.0f]}];

            [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:136/255.0 green:138/255.0 blue:143/255.0 alpha:1.0]} range:[label3.text rangeOfString:[NSString stringWithFormat:@"(%@%@)",[ZCTool sharedInstance].currentSelectedHuoBiDic[@"code"],FORMAT_PRICE(dic[@"targetMoney"])]]];
            label3.attributedText = string;
            NSNumber *statusNum = dic[@"status"];
            label4.text = statusNum.integerValue==1?@"已汇":@"未汇款";
        }
        return cell;
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        NSDictionary *dic = self.wuYeArray[indexPath.row];
        NSString *typeCodeString = dic[@"typeCode"];
        BOOL isHouse = [typeCodeString isEqualToString:@"HOUSE"];
        UILabel *fangJianHaoLabel = [cell viewWithTag:6];
        fangJianHaoLabel.hidden = !isHouse;
        UILabel *titleLabel = [cell viewWithTag:1];
        NSString *buildingNameString = [NSString stringWithFormat:@"%@",dic[@"buildingName"]];
        NSString *fangJianHaoString = [NSString stringWithFormat:@"#%@",dic[@"roomNum"]];
        if (isHouse) {
            fangJianHaoLabel.text = fangJianHaoString;
            CGFloat width = [UIScreen mainScreen].bounds.size.width - 24.0f;
            /**
             5.根据text的font和字符串自动算出size（重点）
             200:你希望的最大宽度
             MAXFLOAT:最大高度为最大浮点数
             **/
            CGSize size1 = [buildingNameString boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
                                                            options:NSStringDrawingUsesLineFragmentOrigin
                                                         attributes:@{NSFontAttributeName:titleLabel.font}
                                                            context:nil].size;
            CGFloat height1 = size1.height;
            CGSize size2 = [[NSString stringWithFormat:@"%@ %@",buildingNameString,fangJianHaoString] boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
                                                            options:NSStringDrawingUsesLineFragmentOrigin
                                                         attributes:@{NSFontAttributeName:titleLabel.font}
                                                            context:nil].size;
            CGFloat height2 = size2.height;
            
            if (height1==height2) {
                titleLabel.text = buildingNameString;
            }else{
                titleLabel.text = [NSString stringWithFormat:@"%@\n",buildingNameString];
            }
            
        }else{
            titleLabel.text = buildingNameString;
        }
        UIImageView *imageView = [cell viewWithTag:2];
        [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",JSXF_HOST_FILE,dic[@"picPath"]]]];
        UILabel *contentLabel = [cell viewWithTag:3];
        contentLabel.text = [NSString stringWithFormat:@"%@",dic[@"buildingAddress"]];
        
        UILabel *buyPriceLabel = [cell viewWithTag:4];
        buyPriceLabel.text = [NSString stringWithFormat:@"%@万円",FORMAT_PRICE(dic[@"JbuyPrice"])];
        UILabel *returnRateLabel = [cell viewWithTag:5];
        NSNumber *returnRate = dic[@"returnRate"];
        returnRateLabel.text = [NSString stringWithFormat:@"%.1f%%",returnRate.floatValue];
        return cell;
    }
}

-(void)chaKanGengDuoAction{
    [self performSegueWithIdentifier:@"toHKLL" sender:nil];
}

-(IBAction)shaiXuanAction{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"公寓" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (self.currentShaiXuanIndex != 1) {
            self.currentShaiXuanIndex = 1;
            self.shaiXuanResultLabel.text = @"公寓";
            [self sendRequestForLoadWuYeData];
        }
    }];
    [alert addAction:action1];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"一栋" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (self.currentShaiXuanIndex != 2) {
            self.currentShaiXuanIndex = 2;
            self.shaiXuanResultLabel.text = @"一栋";
            [self sendRequestForLoadWuYeData];
        }
    }];
    [alert addAction:action2];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:action3];
    [self presentViewController:alert animated:YES completion:nil];

}
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"toDetail"]) {
        DetailSuperViewController *vc = segue.destinationViewController;
        UITableViewCell *cell = sender;
        NSIndexPath *indexPath = [self.secTableView indexPathForCell:cell];
        NSDictionary *dic = self.wuYeArray[indexPath.row];
        vc.dataId = dic[@"id"];
        vc.isGongYu = [dic[@"typeCode"] isEqualToString:@"HOUSE"];
    }else if ([segue.identifier isEqualToString:@"toWeb"]) {
        WebViewController *vc = segue.destinationViewController;
//        vc.isPDF = YES;
        vc.requestURLString = [NSString stringWithFormat:@"%@",sender];
    }
}
@end
